﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class CreditList : System.Web.UI.UserControl
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Administrator"))
        {
            Response.Redirect("~/Account/Login.aspx");
        }
        foreach (GridViewRow item in GridView1.Rows)
        {
            int creditID = Convert.ToInt32(GridView1.DataKeys[item.RowIndex]["CreditID"].ToString());
            var currencyName = from creditCurrencies in db.CreditCurrencies where creditCurrencies.CreditId == creditID select creditCurrencies.Currency.Name;
            item.Cells[6].Text = "";
            foreach (string name in currencyName)
            {
                item.Cells[6].Text += (name + "; ");
            }
        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
            e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + e.Row.RowIndex);
        }
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string creditId = GridView1.DataKeys[GridView1.SelectedIndex]["CreditID"].ToString();
        Session.Add("id", creditId);
        Response.Redirect("~/Admin/CreditCreatorEdit.aspx");
    }

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
}